package com.mingqijia.gassafety.authority.security.oauth;

import org.springframework.security.access.AccessDecisionManager;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.authentication.InsufficientAuthenticationException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Collection;
import java.util.Objects;

/**
 * @author Damon S.
 * @version v0.2
 * @date 2022-02-27 13:26
 */
@Component
public class JwtAccessDecisionManager implements AccessDecisionManager {

    @Override
    public void decide(Authentication authentication, Object object,
                       Collection<ConfigAttribute> configAttributes)
            throws AccessDeniedException, InsufficientAuthenticationException {
        /*for (ConfigAttribute attribute : configAttributes) {
            String needAuthority = attribute.getAttribute();
            if (StringUtils.isEmpty(needAuthority)) {
                continue;
            }
            for (GrantedAuthority authority : authentication.getAuthorities()) {
                if (Objects.equals(authority.getAuthority(), needAuthority)) {
                    return;
                }
            }
        }
        throw new AccessDeniedException("权限不足");
        */
    }

    @Override
    public boolean supports(ConfigAttribute configAttribute) {
        return false;
    }

    @Override
    public boolean supports(Class<?> aClass) {
        return false;
    }
}
